home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / ZFILTER2.C < prev    next >
C/C++ Source or Header  |  1991-11-26  |  3KB  |  116 lines

  1. /* Copyright (C) 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* zfilter2.c */
  21. /* Additional filter creation for Ghostscript */
  22. #include "ghost.h"
  23. #include "errors.h"
  24. #include "oper.h"
  25. #include "alloc.h"
  26. #include "stream.h"
  27.  
  28. /* Imported from zfilter.c */
  29. int filter_read(P3(os_ptr, stream_procs _ds *, stream **));
  30. int filter_write(P3(os_ptr, stream_procs _ds *, stream **));
  31.  
  32. /* .filterASCII85Encode */
  33. extern stream_procs s_A85E_procs;
  34. int
  35. zA85E(os_ptr op)
  36. {    return filter_write(op, &s_A85E_procs, NULL);
  37. }
  38.  
  39. /* .filterASCII85Decode */
  40. extern stream_procs s_A85D_procs;
  41. int
  42. zA85D(os_ptr op)
  43. {    return filter_read(op, &s_A85D_procs, NULL);
  44. }
  45.  
  46. /* .filterNullEncode */
  47. extern stream_procs s_NullE_procs;
  48. int
  49. zNullE(os_ptr op)
  50. {    return filter_write(op, &s_NullE_procs, NULL);
  51. }
  52.  
  53. /* .filterRunLengthEncode */
  54. #if 0                    /* ****** */
  55. extern stream_procs s_RLE_procs;
  56. extern void s_RLE_init(P2(stream *, uint));
  57. int
  58. zRLE(register os_ptr op)
  59. {    stream *s;
  60.     int code;
  61.     check_type(*op, t_integer);
  62.     if ( (ulong)(op->value.intval) > max_uint )
  63.         return e_rangecheck;
  64.     code = filter_write(op - 1, &s_RLE_procs, &s);
  65.     if ( code < 0 ) return code;
  66.     s_RLE_init(s, (uint)(op->value.intval));
  67.     pop(1);
  68.     return 0;
  69. }
  70. #endif                    /* ****** */
  71.  
  72. /* .filterRunLengthDecode */
  73. #if 0                    /* ****** */
  74. extern stream_procs s_RLD_procs;
  75. extern void s_RLD_init(P1(stream *));
  76. int
  77. zRLD(os_ptr op)
  78. {    stream *s;
  79.     int code = filter_write(op, &s_RLD_procs, &s);
  80.     if ( code < 0 ) return code;
  81.     s_RLD_init(s);
  82.     return 0;
  83. }
  84. #endif                    /* ****** */
  85.  
  86. /* .filterSubFileDecode */
  87. /****** Only implemented for null case (count=0, null string) ******/
  88. extern stream_procs s_SFD_procs;
  89. int
  90. zSFD(os_ptr op)
  91. {    int code;
  92.     check_type(op[-1], t_integer);
  93.     check_type(*op, t_string);
  94.     if ( op[-1].value.intval < 0 ) return e_rangecheck;
  95.     if ( op[-1].value.intval != 0 || r_size(op) != 0 )
  96.         return e_undefined;    /* NYI */
  97.     code = filter_read(op - 2, &s_SFD_procs, NULL);
  98.     if ( code < 0 ) return code;
  99.     pop(2);
  100.     return 0;
  101. }
  102.  
  103. /* ------ Initialization procedure ------ */
  104.  
  105. op_def zfilter2_op_defs[] = {
  106.     {"1.filterASCII85Encode", zA85E},
  107.     {"1.filterASCII85Decode", zA85D},
  108.     {"1.filterNullEncode", zNullE},
  109. #if 0                    /* ****** */
  110.     {"2.filterRunLengthEncode", zRLE},
  111.     {"1.filterRunLengthDecode", zRLD},
  112. #endif                    /* ****** */
  113.     {"1.filterSubFileDecode", zSFD},
  114.     op_def_end(0)
  115. };
  116.